package com.test.controller;

import com.alibaba.fastjson.JSON;
import com.test.config.TestConfig;
import jakarta.annotation.Resource;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@Slf4j
@RestController
public class ApiController {

    @Resource
    private RestTemplate restTemplate;
    @Resource
    private TestConfig testConfig;

    @GetMapping("/api/test")
    public String getApi() {
        log.info("api/test被请求");
        log.info("读取配置：{}", JSON.toJSONString(testConfig));
        return "Hello World I'm test2-service";
    }

    @GetMapping("/api/req/test1")
    public String reqTest1() {
        log.info("api/req/test1被请求");
        return restTemplate.getForObject("http://test1-service:8080/test1/api/test", String.class);
    }
}
